package com.aizuda.boot.modules.business.contract.mapper;

import com.aizuda.boot.modules.business.contract.entity.EmployeeRecentContractTypeEntity;
import com.aizuda.boot.modules.business.contract.entity.ContractTypeEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 员工最近使用合同类型 Mapper 接口
 */
@Mapper
public interface EmployeeRecentContractTypeMapper extends BaseMapper<EmployeeRecentContractTypeEntity> {
    // 查询员工最近使用的合同类型
    @Select("SELECT ct.*, pct.type_name AS parentTypeName " +
            "FROM employee_recent_contract_types erct " +
            "JOIN contract_type ct ON erct.contract_type_id = ct.id " +
            "LEFT JOIN contract_type pct ON ct.parent_id = pct.id " +
            "WHERE erct.employee_id = #{employeeId} AND erct.is_active = 1 " +
            "ORDER BY erct.last_used_date DESC " +
            "LIMIT #{limit}")
    List<ContractTypeEntity> findRecentContractTypes(@Param("employeeId") Long employeeId,
                                                     @Param("limit") int limit);

    /**
     * 根据员工ID和合同类型ID查询记录
     * @param employeeId 员工ID
     * @param contractTypeId 合同类型ID
     * @return 员工最近合同类型记录
     */
    EmployeeRecentContractTypeEntity selectByEmployeeIdAndContractTypeId(
            @Param("employeeId") Long employeeId, 
            @Param("contractTypeId") Integer contractTypeId);
}